<?php
class caf extends controller{

	function caf()
	{
	 	parent::Controller();
		$this->load->helper(array('url','form'));
		$this->load->library(array('session','check_users'));
       // $this->check_users->is_alive(); 
		$this->load->model('caf_model');
        
      
	}
	
  function select_batchcard()
  {
  	$this->check_users->is_alive();
    $this->load->helper('flexigrid');
    $user_ses = $this->session->userdata('userlogindetails');
    $displayform = '';
    if($user_ses['user_id'] && ($user_ses['user_group'] == 2))
    {
        $displayform .='<div id=dashboard ><span>Batch Card Details</span> <a href='.base_url().'/idea_home/general_dashboard ><img align=right src="'.base_url().'images/home.png" alt="home" /></a><img align=right src="'.base_url().'images/back.png" id="back"" alt="back" ONCLICK="history.go(-1)" /></div>';
        $displayform .= '<span style="float:left;">Welcome '.$user_ses['user_name'].'</span><div id=logout><a href="'.base_url().'idea_home/logout">Logout</a></div>';
        $batch = $this->caf_model->get_batch_dataentry();
        
        $displayform .= '<br/>';
        $displayform .='<table width=60% border=1 align=center>';
          $displayform .='<tr>';
          $displayform .='<td align=center>';
          $displayform .='<b>Sl No.</b>';
          $displayform .='</td>';
          $displayform .='<td align=center>';
          $displayform .='<b>Batch Details</b>';
          $displayform .='</td>';
          $displayform .='</tr>';
          $i=1;
          foreach ($batch->result_array() as $row)
          {
            $displayform .='<tr>';
            $displayform .='<td align=center>';
            $displayform .= $i;
            $displayform .='</td>';
            $displayform .='<td align=center>';
            $displayform .= '<a href="'.base_url().'caf/set_batchnum/'.$row['batch_number'].'" id=batch_num >'.$row['batch_number'].'</a>';
            $displayform .='</td>';
            $displayform .='</tr>';
            $i++;
          }
          
          
          $displayform .='</table>';
        
          $data = array('formdisplay'=>$displayform,);  
          
          $this->template->write_view('header','header', $data, True);
          $this->template->write_view('content', 'other_general');
          $this->template->render();
          
          
          
    }
    else
    {
      echo "Forbidden to access!!!";
    }
      
  }

  function set_batchnum($batch=0)
  {
    $user_ses = $this->session->userdata('userlogindetails');
    
    if($user_ses['user_id'] && ($user_ses['user_group'] == 2))
    {
        $this->session->set_userdata('batch_num',$batch);
        redirect("caf/bc_details"); 
    }
    else
    {
      echo "Forbidden to access!!!";
    }
  }
  
	function bc_details()
	{
		$this->load->helper('flexigrid');
		
		$displayform = '';
    $user_ses = $this->session->userdata('userlogindetails');
    
    if($user_ses['user_id'] && ($user_ses['user_group'] == 2))
    {
    		$displayform .='<div id=dashboard ><span>Batch Card Details</span> <a href='.base_url().'/idea_home/general_dashboard ><img align=right src="'.base_url().'images/home.png" alt="home" /></a><img align=right src="'.base_url().'images/back.png" id="back"" alt="back" ONCLICK="history.go(-1)" /></div>';
         $displayform .= '<span style="float:left;">Welcome '.$user_ses['user_name'].'</span><div id=logout><input type="button" id="quick_entry" value="Quick Entry" />&nbsp;<a href="'.base_url().'idea_home/logout">Logout</a></div><br/>';
    		//$displayform .='<div style="float:right;"></div>';
    		$displayform .= '<br/>';
    				
    		$displayform .= '<table id="flex1" style="display:none" border=0 align=left ></table>';
    		
    		$colModel['sl_num'] = array('Sl No',100,TRUE,'center',0);
    		$colModel['batch_number'] = array('Batch Number',150,TRUE,'center',0);
    		$colModel['batch_mobilenum'] = array('Phone Number',150,TRUE,'center',2);
    		$colModel['activation_date'] = array('Activation Date',100,TRUE,'center',0);
    		$colModel['received_date'] = array('Received Date',100,TRUE,'center',0);
        $colModel['caf_entry'] = array('Data Entry',100,TRUE,'center',0);
        $colModel['qc_check'] = array('Validation',100,TRUE,'center',0);
        
    		$gridParams = array(
    			'width' => 'auto',
    			'height' => 'auto',
    			'rp' => 20,
    			'rpOptions' => '[10,20,30,40,50]',
    			'pagestat' => 'Displaying:{from} to {to} of {total} items.',
    			'blockOpacity' => 0.5,
    			'title' => 'Batch Card Details to be processed',
    			'showTableToggleBtn' => true
    		);
    		
    		$grid_js = build_grid_js('flex1',site_url("/ajax/phonenum_list"),$colModel,'sl_num','asc',$gridParams);
    		
    		$data['js_grid'] = $grid_js;	
    		$data = array('formdisplay'=>$displayform,'js_grid'=>$grid_js );	
    		$this->template->add_css('css/flexigrid/flexigrid.css');
    		$this->template->add_js('js/flexigride/jquery.pack.js');
    		$this->template->add_js('js/flexigride/flexigrid.pack.js');
    		
        $this->template->add_js('
        
        $(window).load(function () {
        $("#quick_entry").focus();
          });
      
      $(document).ready(function()
      {
        $("#quick_entry").click(function()
        {
          var url = "'.base_url().'caf/data_entry/1";    
                            
          window.location.href = url;
        });
      });
        
        ','embed');
    		//ends here....
    		$this->template->write_view('header','header', $data, True);
    		$this->template->write_view('content', 'other_general');
    		$this->template->render();
    	}
      else
      {
         echo "Forbidden to access!!!";
      }
		
	}
	
	function data_entry($sl_no = 1)
	{
	
    
    $user_ses = $this->session->userdata('userlogindetails');
    if($user_ses['user_id'] && ($user_ses['user_group'] == 2))
    {
      $batch_num = $this->session->userdata("batch_num");
  	 
         
        $result = $this->caf_model->fetch_batchdetails($batch_num,$sl_no);
        $val = $result->result_array();
        
  		$displayform = '';
      
      if($val)
      {
        $sl_num = $val[0]['sl_num'];
        $batch_id = $val[0]['batch_id'];
        $mobile = $val[0]['batch_mobilenum'];
       
  		$displayform .='<div id=dashboard ><span>Data Entry</span>&nbsp;<a href='.base_url().'/idea_home/general_dashboard ><img align=right src="'.base_url().'images/home.png" alt="home" /></a></div>';
  		$displayform .= '<span style="float:left;">Welcome '.$user_ses['user_name'].'</span><div id=logout><a href="'.base_url().'caf/bc_details">View CAF Details</a>&nbsp;<a href="'.base_url().'idea_home/logout">Logout</a></div>';
  		$attr = array('id'=>'data_entry_form');
  		$displayform .= form_open('caf/save_entry',$attr);
		$displayform .= '<div> &nbsp;</div>';
  		$displayform .= '<div id=div_entry>';
		$displayform .= '<fieldset><legend>CAF Info</legend>';
		
		$displayform .='<table width=100% >';
		$displayform .='<tr>';
		$displayform .='<td><B>Batch No:</B><span id=batch_no style="color:#999999" >'.$batch_num.'</span>';
		$displayform .= '<input type=hidden name="batch_id" value="'.$batch_id.'" />';
		$displayform .='</td>';
		$displayform .='<td>';
		$displayform .= '<b>SL No:</b><input type="text" name="sl_num" id="sl_num" value='.$sl_num.' size="2" /><input type="button" id="quick_entry" name=Quick value="Retrive"/>';
		
		$displayform .='</td>';
		$displayform .='<td>';
		$displayform .= '<b>Mobil Num:</b>';
  		$displayform .= '<input type=text name=mobile_num size=10 value="'.$mobile.'" disabled=disabled />';
  		
		$displayform .='</td>';
		$displayform .='</tr>';
		
		$displayform .='<tr>';
		$displayform .='<td>';
		
		$displayform .= '<b>CAF Filed On:</b>'; 
  		$date_num = date("d-m-Y");
		$displayform .= '<input type=text name =filled_on_date id=filled_on_date size=10 value='.$date_num.' disabled=disabled /></span>';
		$displayform .='</td>';
		$displayform .='<td>';
		$displayform .= '<b>Retailer Name:</b><input type="text" name="retailer_name" id="retailer_name" size=15 />';
	   
		$displayform .='</td>';
		$displayform .='<td>';
		 $displayform .='<b>Sim No:</b><input type="text" name=sim_no id="sim_no"  /> ';
		$displayform .='</td>';
		$displayform .='</tr>';
		
		$displayform .='</table>';
		$displayform .= '</fieldset>';
		
	    $displayform .= '</div>';

  		$displayform .= '<div id=personal1><fieldset><legend>Personal Details</legend>';
  		$displayform .= '<table align=left width=100% >';
  		$displayform .= '<tr><td colspan=6><span id=salutation> Salutation:';
  		$displayform .= '&nbsp;<select name=salutation  ><option value=Mr> Mr.</option>';
  		$displayform .= '<option value=Mrs>Mrs.</option>';
  		$displayform .= '<option value=Ms>Ms.</option>';
  		$displayform .= '<option value=Dr>Dr.</option>';
  		$displayform .= '</select>';
  		$displayform .= '</span>';
  		$displayform .= '<span id=sex>Sex:';
  		$displayform .= '&nbsp;<select name=sex ><option value=M>M</option>';
  		$displayform .= '<option value=F>F</option></select></span>';
	      $displayform .= '<span id=martial >Marital:';
	      $displayform .= '&nbsp;<select name=marital >';
	      $displayform .= '<option value=S>Single</option>';
	      $displayform .= '<option value=M>Married</option>';
	      $displayform .= '</select>';
	      $displayform .= '</span>';
  		$displayform .= '<span id=dob>DOB:';
  		$displayform .= '&nbsp;<input type=text name =dob id=idob size=10 class="datepicker"  /></span></td>';
  		$displayform .= '</tr>';
  		$displayform .= '<tr><td align=right>';
  		$displayform .= 'Customer Name:</td>';
  		$displayform .= '<td colspan=5><input type=text name=customer_name id=cust_name value="only text and hypen is allowed" style="color:#cccccc;" class=autobox size=45 /></td></tr>';
  		$displayform .= '<tr>';
  		$displayform .= '<td align=right>Father Name:</td>';
  		$displayform .= '<td colspan=5><input type=text name=father_name id="father_name" value="only text and hypen is allowed" style="color:#cccccc;" id=father_name class=autobox size=45 /></td></tr>';
  		$displayform .= '<tr><td align=right>Nationality:</td>';
  		$displayform .= '<td><select name=nationality ><option value=Indian>Indian</option>';
  		$displayform .= '<option value=Foreigner>Foreigner</option></select>';
  		$displayform .= '</td>';
      $displayform .= '<td>Add Type:';
      $displayform .= '<select name=add_type  >';
      $displayform .= '<option value="R">R</option>';
      $displayform .= '<option value="O">O</option>';
      $displayform .= '</select>';
      $displayform .= '</td>';
      
      $displayform .= '<td>';
      $displayform .= '&nbsp;'; 
      $displayform .= '</td>';
  	  $displayform .= '<td>';
      $displayform .= '&nbsp;'; 
      $displayform .= '</td>';
  		$displayform .= '</tr>';
  	
    
  		$displayform .= '</table>';
  		$displayform .= '</fieldset></div>';
      
         
  		$displayform .= '<div id="personal2"><fieldset><legend>Personal Details</legend>';
  		$displayform .= '<table align=left width=50%  >';
  		$displayform .= '<tr>';
  		$displayform .= '<td align=right>POI Type:</td>';
  		$displayform .= '<td><select name="poi_type1">';
  		
  		$poi_name = $this->caf_model->fetch_poi();
  		
  		foreach($poi_name ->result_array() as $row)
  		{
  			$displayform .= '<option value='.$row['poi_id'].'>'.$row['poi_desc'].'</option>';
  		}
  		  		 		
  		$displayform .= '</select></td>';
  	
  		$displayform .= '</tr>';
  		$displayform .= '<tr>';
  		$displayform .= '<td align=right>POI Num:</td>';
  		$displayform .= '<td><input type=text name=poi_num1 id="poi_num1" value="No Special Character, only alpha/numeric" style="color:#cccccc;"  id=poi_num1 class=autobox size=30 /></td>';
  
  		$displayform .= '</tr>';
  		$displayform .= '</table>';
      
      $displayform .= '<table align=left width=50% >';
      $displayform .= '<tr>';
      $displayform .= '<td align=right>POA Type:</td>';
      $displayform .= '<td><select name="poi_type2">';
      
      foreach($poi_name ->result_array() as $row)
      {
        $displayform .= '<option value='.$row['poi_id'].'>'.$row['poi_desc'].'</option>';
      }
      
      $displayform .= '</select></td>';
      $displayform .= '</tr>';
      $displayform .= '<tr>';
      $displayform .= '<td align=right>POA Num:</td>';
      $displayform .= '<td><input type=text name=poi_num2 id=poi_num2 value="No Special Character, only alpha/numeric" style="color:#cccccc;"  class=autobox size=30 /></td>';
      $displayform .= '</tr>';
      $displayform .= '</table>';
      
  		$displayform .= '</fieldset></div>';
		
  		$displayform .= '<div>';
		$displayform .='<table width=100% >';
		$displayform .='<tr>';
		$displayform .='<td width=50%>';
		$displayform .= '<fieldset><legend>Local Address</legend>';
  		$displayform .= '<table align=left width=100%  >';
	       
  		$displayform .= '<tr>';
  		$displayform .= '<td align=right>Address:</td>';
  		$displayform .= '<td><input type=text name=doc_addr_num id=doc_addr_num size=20 value="Door No/Flat No/House No" class=autobox style="color:#cccccc;" /></td>';
  		$displayform .= '</tr>'; 
  		$displayform .= '<tr>';
  		$displayform .= '<td >&nbsp;</td><td align=left><input type=text name=doc_addr_cross id=doc_addr_cross value="Cross,Main Stage,Block"  class=autobox style="color:#cccccc;"  />';
  		$displayform .= '</td>';
  		$displayform .= '</tr>';
  		$displayform .= '<tr>';
  		$displayform .= '<td align=right>State:</td>';
  		$displayform .= '<td align=left ><select name=doc_state id=doc_state_name style="width:200px;" >';
  		$displayform .= '<option value=" ">Please select state</option>';
  		$tate_name = $this->caf_model->fetch_state();
  		foreach($tate_name ->result_array() as $row)
  		{
  			$displayform .= '<option value='.$row['state_id'].'>'.$row['state_name'].'</option>';
  		}
  		$displayform .= '</select>';
  		$displayform .= '</td>';
  		$displayform .= '</tr>';
  		$displayform .= '<tr>';
  		$displayform .= '<td align="right">City/District:</td><td>';
  		$displayform .= '<span id=document_city><select name=doc_city_name id=doc_city >';
  	    $displayform .= '<option value=""></option>';	
  	    $displayform .= '</select></span>';
  		$displayform .= '</td>';
  		$displayform .= '</tr>';
  		$displayform .= '<tr>';
  		$displayform .= '<td align=right>Area:</td>';
  		
  		$displayform .= '<td>';
  		$area_name = $this->caf_model->fetch_area();
  
  		$displayform .= '<span id=span_doc_area> <select name="doc_area_name"  id="doc_area">';
  		$displayform .= '<option value=""></option>';				
  		$displayform .= '</select></span>';
  		
  		$displayform .='Pincode:<span id="span_doc_pin"><input type=text name=doc_pincode id=doc_pin size=6/></span></td>';
  		$displayform .= '</tr>';
      
      $displayform .= '<tr>';
      $displayform .= '<td align="right">Phone1:';
     
      $displayform .= '</td>';
      $displayform .= '<td>';
      $displayform .= '<input type="text" name="loc_ph1" id="loc_ph1" size=10 />&nbsp;';
      $displayform .= 'Phone2:<input type="text" name="loc_ph2" id="loc_ph2" size=10 />';
      $displayform .= '</td>';
     
      $displayform .= '</tr>';
       $displayform .= '<tr>';
     
       $displayform .= '<tr>';
      $displayform .= '<td align="right">Cont Person:';
     
      $displayform .= '</td>';
      $displayform .= '<td>';
      $displayform .= '<input type="text" name="cont_person" id="cont_person" size=10 />';
      $displayform .= '</td>';
     
      $displayform .= '</tr>';
  		$displayform .= '</table>';
  		$displayform .= '</fieldset>';
		$displayform .='</td>';
		$displayform .='<td>';
		$displayform .= '<fieldset><legend>Permanent Address</legend>';
  		$displayform .= '<table align=left width=100% >';
  		$displayform .='<tr>';
        $displayform .='<td colspan =2 >';
	        $displayform .='<input name="same_loc_addr" type="checkbox" id="same_loc" /> &nbsp;';
	        $displayform .='Local and Alternate Address as same';  
	        $displayform .='</td>';
	        $displayform .='</tr>';
  		$displayform .= '<tr>';
  		$displayform .= '<td align=right>Address:</td>';
  		$displayform .= '<td><input type=text name=alt_addr_num value="Door No/Flat No/House No" style="color:#cccccc;" id=alt_num class=autobox /></td>';
  		$displayform .= '</tr>';
  		$displayform .= '<tr>';
  		$displayform .= '<td >&nbsp;</td><td align=left><input type=text name=alt_addr_cross id=alt_cross value="Cross,Main Stage,Block" style="color:#cccccc;" class=autobox />';
  		$displayform .= '</td>';
  		$displayform .= '</tr>';
		$displayform .= '<tr>';
  		$displayform .= '<td align=right>Country:</td>';
  		$displayform .= '<td align=left>';
		$displayform .= '<select name=country id=country style="width:200px;">';
		$displayform .= '<option value="India">India</option>';
		$country = $this->caf_model->get_countries();
		$ctry_name = $country->result_array();
		foreach($ctry_name as $row)
		{
			$displayform .='<option value='.$row['country_name'].' >'.$row['country_name'].'</option>';
		}
		
		$displayform .= '</select>';
  		$displayform .= '</td>';
  		$displayform .= '</tr>';
  		$displayform .= '<tr>';
  		$displayform .= '<td align=right>State:</td>';
  		$displayform .= '<td align=left ><span id="fr_state"><select name=alt_state id=alt_state_name style="width:200px;" >';
  		
  		$tate_name = $this->caf_model->fetch_state();
		$dispOption = '';
		$displayform .= '<option value=" ">Please select state</option>';
  		foreach($tate_name ->result_array() as $row)
  		{
  			$dispOption .= '<option value='.$row['state_id'].'>'.$row['state_name'].'</option>';
  		}
		$displayform .= $dispOption;
	//	echo $dispOption;exit;
  		$displayform .= '</select></span>';
  		$displayform .= '</td>';
  		$displayform .= '</tr>';
  		$displayform .= '<tr>';
  		$displayform .= '<td align=right>City/District:</td><td align=left><span id=alternate_city>';
  		$displayform .= '<select name=alt_city_name  id=alt_city >';
  		$displayform .= '<option value=""></option>';

  		$displayform .= '</select></span>';
  		
  		
  		$displayform .= '</td>';
  		$displayform .= '</tr>';
  		$displayform .= '<tr>';
  		$displayform .= '<td align=right>Area:</td>';
  		
  		$displayform .= '<td>';
  		$displayform .= '<span id=span_alt_area ><select name="alt_area_name" id=alt_area>';
  		$displayform .= '<option value="">please select area</option>';
  		
  		$displayform .= '</select></span>';
  		$displayform .= 'Pincode:<span id=span_alt_pin><input type=text name=alt_pincode id=alt_pin size=6 /></span></td>';
  		$displayform .= '</tr>';
  		$displayform .= '</table>';
  		$displayform .= '</fieldset>';
		$displayform .='</td>';
		$displayform .='</tr>';
		
		$displayform .='</table>';
		$displayform .= '</div>';
		
		
		$displayform .= '<div>';
		$displayform .='<table width=100%>';
		$displayform .='<tr>';
		$displayform .='<td width=50%>';
		$displayform .= '<fieldset><legend>Local Refree Details</legend>';
  		$displayform .= '<table align=left >';
		$displayform .= '<tr>';
  		$displayform .= '<td align=right>Ref Name:</td>';
  		$displayform .= '<td><input type=text name=ref_name value="Referrer Name" id="ref_name" style="color:#cccccc;"  class=autobox /></td>';
  		$displayform .= '</tr>';
		$displayform .= '<tr>';
  		$displayform .= '<td align=right>Ref Phone:</td>';
  		$displayform .= '<td><input type=text name=ref_ph value="Referrer phone" id="ref_ph" style="color:#cccccc;"  class=autobox /></td>';
  		$displayform .= '</tr>';
  		$displayform .= '<tr>';
  		$displayform .= '<td align=right>Address:</td>';
  		$displayform .= '<td><input type=text name=loc_addr_num value="Door No/Flat No/House No" id="loc_addr_num" style="color:#cccccc;"  class=autobox /></td>';
  		$displayform .= '</tr>';
  		$displayform .= '</table>';
  		$displayform .= '</fieldset>';
		
  
		$displayform .='</td>';
		$displayform .='<td >';
	
        
      
  		$displayform .= '<fieldset><legend style="color:blue;">Page Info</legend>';
  		$displayform .= '<table  width=100% >';
  		$displayform .= '<tr>';
  		$displayform .= '<td align=right width=20%>NOP:</td><td align=left width=80%><input type=text name="nop" id="nop" size=1 maxlength=2 /></td>';
  		$displayform .= '</tr>';
  		$displayform .= '<tr>';
  		$displayform .= '<td align=right >BLD RGN:</td><td align=left><input type=text name="bld_reg" id="bld_reg" size=4 />';
  		$displayform .= '</td>';
  		$displayform .= '</tr>';
  		$displayform .= '<tr>';
  		
  		$displayform .= '<tr>';
  		$displayform .= '<td colspan=2 align=center> <input type=submit id=submit_data value=Save "> &nbsp;&nbsp;<input type=reset value=Cancel "></td>';
  		$displayform .= '</tr>';
  		$displayform .= '</table>';
  		$displayform .= '</fieldset>';
  	
		$displayform .='</td>';
		$displayform .='</tr>';

		$displayform .='</table>';
		
  		$displayform .= form_close();
  	
		
		$displayform .= '</div>';
      
  		}
      else
      {
              $displayform .= '<div id=dashboard ><span>Data Entry</span>&nbsp;<a href='.base_url().'/idea_home/general_dashboard ><img align=right src="'.base_url().'images/home.png" alt="home" /></a></div>';
              $displayform .= '<span style="float:left;">Welcome '.$user_ses['user_name'].'</span><div id=logout><a href="'.base_url().'caf/bc_details">View CAF Details</a>&nbsp;<a href="'.base_url().'idea_home/logout">Logout</a></div>';
              $displayform .= '<br/>';
              $displayform .= '<div style="float:center;">No Data available to process,please select new Batch Number to process!!</div>';
              $displayform .= '<br/>';
      }  
      	
  		$data = array('formdisplay'=>$displayform );
  
  		
  		
  		$this->template->add_js('js/ui/jquery.ui.datepicker.js');
  		$this->template->add_js('js/jquery.autobox.js');
  		
  		$this->template->add_js('js/ui/jquery.ui.position.js');
  		$this->template->add_js('js/ui/jquery.ui.autocomplete.js');
  		$this->template->add_js('js/caf/caf.js');
		$space =" ";
		if(!isset($dispOption))
			{
				$dispOption ='';
			}
		$this->template->add_js('
		
		$(document).ready(function(){
			
 	$("#country").change(function(){
 		var country = $("#country").val();
		
 		if(country =="India")
 		{
 			$("#fr_state").replaceWith("<span id=fr_state><select name=alt_state id=alt_state_name><option value='.$space.'>Please select state</option>'.$dispOption.'</select></span>");
			$("#alternate_city").replaceWith("<span id=alternate_city><select name=alt_city_name  id=alt_city ></select></span>");
			$("#alt_state_name").css("width","200px");
			$( "#alt_city" ).combobox_alt_city();
			$(document).ready(function(){
			$("#alt_state_name").change(function(){
				var src = $(this).val();

			 	$.ajax({
			type: "GET",
			url: "/caf/alt_display_cities/"+ src,

			dataType: "text/html",
			success: function(html){       $("#alternate_city").html(html); 
						$(function() {
						$( "#alt_city" ).combobox_alt_city();
		
	});
			    }

			  });

			});
			});
			
			$("#span_alt_area").replaceWith("<span id=span_alt_area ><select name=alt_area_name id=alt_area></select></span>");
			$( "#alt_area" ).combobox_alt_area();
			$(document).ready(function(){
	$("#alternate_city").focusout(function(){
	var src = $("#alt_city").val();
		
		
		$.ajax({
			type: "GET",
			url: "/caf/alt_display_areas/"+ src,

			dataType: "text/html",
			success: function(html){       $("#span_alt_area").html(html); 
			
		$(function() {
		$( "#alt_area" ).combobox_alt_area();
			});
			    }

			  });
		
		
		});
		
		
	});	
	
		//to place pincode in alternate address field...
	$(document).ready(function(){
		$("#span_alt_area").focusout(function(){
			var src = $("#alt_area").val();	
						
			$.ajax({
			type: "GET",
			url: "/caf/alt_display_pin/"+ src,

			dataType: "text/html",
			success: function(html){       $("#span_alt_pin").html(html); 
			
			    }

			  });
			
		});
	});
	
 		}
 		else
 		{
 			$("#fr_state").replaceWith("<span id=fr_state><input type=text name=foriegn_state id=foriegn_state /></span>");
 			$("#alternate_city").replaceWith("<span id=alternate_city><input type=text name=foriegn_city id=foriegn_city /></span>");
			$("#span_alt_area").replaceWith("<span id=span_alt_area ><input type=text name=foriegn_area id=foriegn_area /></span>");
 		}
 	});
 });
		
		','embed');
      $this->template->add_js('js/caf/caf_validation.js');
  		
      $this->template->add_js('
  			$(function() {
  			$( ".datepicker" ).datepicker(			
  			{
  			dateFormat: "dd/mm/yy",
  			yearRange: "1900:2010",
  			changeMonth: true,
  			changeYear: true,
  			showOn: "button",
  			buttonImage: "'.base_url().'images/calendar.gif",
  			buttonImageOnly: true
  		
  		});
  		
  		});
  
  		','embed');
  		
  		$this->template->add_js('
  		
              $(document).ready(function(){
               
                              $("#quick_entry").click(function(){
                              var sl_no = $("#sl_num").val();
                              var url = "'.base_url().'caf/data_entry/"+sl_no;    
                            

                              window.location.href = url;
                            
                              });
                            });
  		
  		','embed');
  	 
       
  		$this->template->write_view('header','header', $data, True);
  		$this->template->write_view('content', 'other_general');
  		$this->template->render();
  		}

      else
      {
        echo "Forbidden to access";
      }
  
	}

/*
  function get_batchdetails($data=0)
  {
    $batch_num = $this->session->userdata("batch_num");
    $res = $this->caf_model->fetch_batchdetails($batch_num,$data);
    $val = $res->result_array();
        
    $details = array('mobile'=>$val[0]['batch_mobilenum'],'sim_num'=>$val[0]['sim_num'],'batch_id'=>$val[0]['batch_id']);
    echo json_encode($details);
    }
 * 
 */
 
	//to save data entered values....
	function save_entry()
	{
		
	 $user_ses = $this->session->userdata('userlogindetails');
	  if($user_ses['user_id'] && ($user_ses['user_group'] == 2))
	 {
		$this->caf_model->data_entry_save();
    
		$sl = $_POST['sl_num']+1;
    
    
		    redirect("caf/data_entry/".$sl);
        
     }
	else
	{
	  echo "Forbidden to access";
	}

    
	}
	
//to for ajax to display cities in document addresss...	
	function doc_display_cities($id=0)
	{
		 $user_ses = $this->session->userdata('userlogindetails');
    if($user_ses['user_id'] && ($user_ses['user_group'] == 2))
    {	
      		$this->load->model('cities_model');
      		$cities= $this->cities_model->disp_cities($id);
      		$ajaxVal = '';
      		$ajaxVal .= '<select name=doc_city_name id=doc_city >';
      		$ajaxVal .= '<option value="" > </option>';
      		foreach ($cities->result_array() as $row)
      		{
      			$ajaxVal .= '<option value="'.$row['city_id'].'">'.$row['city_name'].'</option>';
      		}
      		$ajaxVal .='</select>';
      		
      		echo $ajaxVal;
    }
    else
    {
      echo "Forbidden to access";
    }
	}
//to for ajax to display areas in document addresss...		
	function doc_display_areas($id=0)
	{
	   $user_ses = $this->session->userdata('userlogindetails');
    if($user_ses['user_id'] && ($user_ses['user_group'] == 2))
    {
    		$this->load->model('area_model');
    		$areas= $this->area_model->disp_areas($id);
    		$ajaxVal = '';
    		$ajaxVal .= '<select name=doc_area_name id=doc_area >';
    		$ajaxVal .= '<option value="" > </option>';
    		foreach ($areas->result_array() as $row)
    		{
    			$ajaxVal .= '<option value="'.$row['area_id'].'">'.$row['area_name'].'</option>';
    		}
    		$ajaxVal .='</select>';
    		
    		echo $ajaxVal;
    }
    else
    {
      echo "Forbidden to access";
    }
	}
	
	//to display pincode in document field...
	function doc_display_pin($id=0)
	{
	  
    $user_ses = $this->session->userdata('userlogindetails');
    if($user_ses['user_id'] && ($user_ses['user_group'] == 2))
    {
    		$this->load->model('area_model');
    		$pincode = $this->area_model->disp_pincode($id);
    		$code = $pincode->result_array();
    		$ajaxVal = '';
    		if($id == 0)
    		{
    			$ajaxVal .= '<input type=text name=doc_pincode value=" " size=6 />';	
    		}
    		else
    		{
    		//$ajaxVal .= print_r($code);
    		$ajaxVal .= '<input type=text name=doc_pincode value="'.$code[0]['area_pincode'].'" size=6 />';
    		}
    		
    		echo $ajaxVal;
    }
    else
    {
      echo "Forbidden to access";
    }
	}
	
	//to for ajax to display areas in alternate addresss...		
	function alt_display_areas($id=0)
	{
	  $user_ses = $this->session->userdata('userlogindetails');
    if($user_ses['user_id'] && ($user_ses['user_group'] == 2))
    {
    		$this->load->model('area_model');
    		$areas= $this->area_model->disp_areas($id);
    		$ajaxVal = '';
    		$ajaxVal .= '<select name=alt_area_name id=alt_area >';
    		$ajaxVal .= '<option value="" > </option>';
    		foreach ($areas->result_array() as $row)
    		{
    			$ajaxVal .= '<option value="'.$row['area_id'].'">'.$row['area_name'].'</option>';
    		}
    		$ajaxVal .='</select>';
    		
    		echo $ajaxVal;
    }
    else
    {
      echo "Forbidden to access";
    }
	}
	
	//to display pincode in alternate field...
	function alt_display_pin($id=0)
	{
	  $user_ses = $this->session->userdata('userlogindetails');
    if($user_ses['user_id'] && ($user_ses['user_group'] == 2))
    {
    		$this->load->model('area_model');
    		$pincode = $this->area_model->disp_pincode($id);
    		$code = $pincode->result_array();
    		$ajaxVal = '';
    		if($id == 0)
    		{
    			$ajaxVal .= '<input type=text name=alt_pincode id="alt_pin" value=" " size=6 />';	
    		}
    		else
    		{
    		//$ajaxVal .= print_r($code);
    		$ajaxVal .= '<input type=text name=alt_pincode id="alt_pin" value="'.$code[0]['area_pincode'].'" size=6 />';
    		}
    		
    		echo $ajaxVal;
 		}
    else
    {
      echo "forbidden to access";
    }
  

	}
		
		function alt_display_cities($id=0)
	{
		$user_ses = $this->session->userdata('userlogindetails');
    if($user_ses['user_id'] && ($user_ses['user_group'] == 2))
    {	
    		$this->load->model('cities_model');
    		$cities = $this->cities_model->disp_cities($id);
    		$ajaxVal = '';
    		$ajaxVal .= '<select name=alt_city_name id=alt_city>';
    		$ajaxVal .= '<option value=" " ></option>';
    		foreach ($cities->result_array() as $row)
    		{
    			$ajaxVal .= '<option value="'.$row['city_id'].'">'.$row['city_name'].'</option>';
    		}
    		$ajaxVal .='</select>';
    		
    		echo $ajaxVal;
    }
    else
    {
      echo "forbidden to access";
    }
	}

	
	function loc_display_cities($id=0)
	{
		 $user_ses = $this->session->userdata('userlogindetails');
    if($user_ses['user_id'] && ($user_ses['user_group'] == 2))
    {	
    		$this->load->model('cities_model');
    		$cities = $this->cities_model->disp_cities($id);
    		$ajaxVal = '';
    		$ajaxVal .= '<select name=loc_city id=loc_city >';
    		$ajaxVal .= '<option value="" ></option>';
    		foreach ($cities->result_array() as $row)
    		{
    			$ajaxVal .= '<option value="'.$row['city_id'].'">'.$row['city_name'].'</option>';
    		}
    		$ajaxVal .='</select>';
    		
    		echo $ajaxVal;
    }
    else
    {
      echo "Forbidden to access";
    }
	}
	
	//to for ajax to display areas in local addresss...		
	function loc_display_areas($id=0)
	{
	  $user_ses = $this->session->userdata('userlogindetails');
    if($user_ses['user_id'] && ($user_ses['user_group'] == 2))
    {
      		$this->load->model('area_model');
      		$areas= $this->area_model->disp_areas($id);
      		$ajaxVal = '';
      		$ajaxVal .= '<select name=loc_area_name id=loc_area >';
      		$ajaxVal .= '<option value="" > </option>';
      		foreach ($areas->result_array() as $row)
      		{
      			$ajaxVal .= '<option value="'.$row['area_id'].'">'.$row['area_name'].'</option>';
      		}
      		$ajaxVal .='</select>';
      		
      		echo $ajaxVal;
    }
    else
    {
      echo "Forbidden to access";
    }
  
	}
	
	//to display pincode in local field...
	function loc_display_pin($id=0)
	{
	  $user_ses = $this->session->userdata('userlogindetails');
    if($user_ses['user_id'] && ($user_ses['user_group'] == 2))
    {
    		$this->load->model('area_model');
    		$pincode = $this->area_model->disp_pincode($id);
    		$code = $pincode->result_array();
    		$ajaxVal = '';
    		if($id == 0)
    		{
    			$ajaxVal .= '<input type=text name=loc_pincode value=" " size=6 />';	
    		}
    		else
    		{
    		//$ajaxVal .= print_r($code);
    		$ajaxVal .= '<input type=text name=loc_pincode value="'.$code[0]['area_pincode'].'" size=6 />';
    		}
    		
    		echo $ajaxVal;
    }
    else
    {
      echo "Forbidden to access";
    }
  
	}
	

		
	
}

